package com.bjsxt.service.impl;

import com.bjsxt.mapper.AdminMapper;
import com.bjsxt.mapper.RoleMapper;
import com.bjsxt.pojo.Admin;
import com.bjsxt.pojo.Menu;
import com.bjsxt.service.AdminService;
import com.bjsxt.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("admins")
public class AdminServiceImpl implements AdminService {

    @Autowired
    AdminMapper  adminMapper;

    @Autowired
    MenuService  menuService;

    @Autowired
    RoleMapper  roleMapper;

    @Override
    public Admin login(String uname, String pwd) {

        return adminMapper.selectOne(uname, pwd);
    }

    @Override
    public Admin findPwd(String username) {

        Admin admin = adminMapper.selectPwd(username);


        List<Menu> list = menuService.findMoreMenus(admin.getRid());

        //把菜单保存到执行的admin对象中
        admin.setList(list);
        //把用户的身份保存admin中
        admin.setRole(roleMapper.selectOne(admin.getRid()));

        return  admin;
    }
}
